<?php
// @formatter:off
/**
 * @file WCParserBehavior.php
 *
 * @author Alejandro Dario Simi
 * @date $Date: 2013-05-13 04:08:49 +0000 (Mon, 13 May 2013) $
 *
 * $Id: WCParserBehavior.php 64 2013-05-13 04:08:49Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/tags/wcomix-1.0-BETA2/includes/parser/WCParserBehavior.php $
 */
// @formatter:on

/**
 * @var string[string]
 * This is the matrix where every known behavior must be specified.
 * Keys are keywords found as function in parsed text, and values are classes'
 * names to be used as parsing handler.
 */
$WCParserBehaviorMatrix = array();

/**
 * @class WCParserBehavior
 * This is an abstract representation of a parser node's behavior (a.k.a.
 * function handler).
 */
class WCParserBehavior {
	/**
	 * @var WCParserNode
	 * Node to which this behavior is attached to.
	 */
	protected $_node = false;
	/** @var boolean Current status. */
	protected $_ok = false;
	/** @var string Last error message. */
	protected $_errorMsg = "Unknown error";
	/**
	 * @var WCParser
	 */
	protected $_parser = null;
	//
	// Constructor.
	/**
	 * @param WCParserNode $node Pointer to the node to which this behavior
	 * affects.
	 */
	public function __construct(WCParserNode &$node) {
		$this->_node = $node;
		$this->_parser = $this->_node->parser();
		$this->init();
	}
	//
	// Public Methods.
	/**
	 * This is an abstract method and it must perform a check of the object,
	 * set the current status (variable $this->_ok) and return that status.
	 *
	 * @warning Subclass Responsibility
	 *
	 * @return boolean Returns the current status after a check.
	 */
	public function check() {
		trigger_error("Subclass Responsibility", E_USER_ERROR);
		return $this->isOk();
	}
	public function errorMessage() {
		return $this->_errorMsg;
	}
	public function isOk() {
		return $this->_ok;
	}
	/**
	 * This is an abstract method and it must parse parameters and contents of
	 * the node and generates a text based on them.
	 *
	 * @warning Subclass Responsibility
	 *
	 * @return string Returns the result string or false in case of errors.
	 */
	public function get() {
		trigger_error("Subclass Responsibility", E_USER_ERROR);
		return false;
	}
	//
	// Protected Methods.
	/**
	 * This method is a generic initializer called by every constructor.
	 */
	protected function init() {
	}
}
?>
